package com.shanzmoo.platform.manage.api.web.sys;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.domain.vo.SysRolePageVO;
import com.shanzmoo.core.domain.vo.SysRoleSelectVO;
import com.shanzmoo.db.module.psys.domain.dto.RoleSaveDTO;
import com.shanzmoo.db.module.psys.domain.dto.RoleUpdateDTO;
import com.shanzmoo.db.module.psys.domain.query.RoleQuery;
import com.shanzmoo.platform.manage.api.manager.SysRoleManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author： Gzhao 2021/3/29
 */
@Api(tags = "系统-角色管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys-role")
public class SysRoleController {

    private final SysRoleManager sysRoleManager;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody RoleSaveDTO saveDto) {
        sysRoleManager.add(saveDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        sysRoleManager.deleteById(id);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody RoleUpdateDTO updateDto) {
        sysRoleManager.edit(updateDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "分页列表")
    @PostMapping("/page-list")
    public SHttpResponse<PageRespBase<SysRolePageVO>> pageList(@Valid @RequestBody RoleQuery queryDto) {
        SResponse<PageRespBase<SysRolePageVO>> re = sysRoleManager.getPageList(queryDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "角色选择列表")
    @GetMapping("/select-list")
    public SHttpResponse<List<SysRoleSelectVO>> getSelectList() {
        List<SysRoleSelectVO> re = sysRoleManager.getSelectList();
        return SHttpResponse.ok(re);
    }
}
